package ex402.exercise;

import java.util.ArrayList;

public class AdditionExercise {
    private ArrayList<AdditionQuestion> questions;

    private int numberOfQuestions;

    public AdditionExercise() {
        questions = new ArrayList<>();
    }

    public void generateQuestions(int numberOfQuestions, int min, int max) {
        this.numberOfQuestions = numberOfQuestions;
        for (int i = 0; i < numberOfQuestions; i++) {
            int a = (int) (Math.random() * (max - min) + min);
            int b = (int) (Math.random() * (max - min) + min);
            AdditionQuestion question = new AdditionQuestion(a, b);
            questions.add(question);
        }
    }

    public AdditionQuestion getQuestion(int index) {
        if (index >= numberOfQuestions) {
            return null;
        } else {
            return questions.get(index);
        }
    }

    public int getNumberOfCorrect() {
        int result = 0;
        for (AdditionQuestion q : questions) {
            if (q.judge()) {
                result++;
            }
        }
        return result;
    }

    public int getNumberOfQuestions() {
        return numberOfQuestions;
    }
}
